version 7.0
log using magimmigration.log, replace
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*   File-Name:  magimmigration_ci.do                                    *;
*   Date:       March 20, 2002                                          *;
*   Author:     MRG                                                     *;
*   Purpose:    Interaction term between immigration and logmag.  Then  *;
*               calculate the conditional coefficients on immigration   *;
*               for Populist parties                                    *;
*   Input File: masterdata.dta                                          *;
*   Output File:magimmigration.log                                      *;
*   Data Output:                                                        *;
*   Previous file:                                                      *;
*   Machine:    system12                                                *;
*     ****************************************************************  *;
*     ****************************************************************  *;


use h:\CPS\Data\masterdata.dta;

generate logmagnitude = ln(magnitude);

*     ****************************************************************  *;
*       Main model in the paper                                         *;
*     ****************************************************************  *;

set more off;

tobit   populist immigration unemployment UnempImmig logmagnitude uppertier
        austria belgium denmark finland france germany greece iceland 
        ireland italy luxembourg malta norway portugal spain 
        sweden switzerland unitedkingdom, ll(0) ltolerance (1e-5);
        
*     ****************************************************************  *;
*       Now create interaction between immigration and logmag.          *;
*       Drop UnempImmig from the model above.  Now see how immigration  *;
*       effect changes conditional on magnitude.                        *;
*     ****************************************************************  *;

generate immigmag= logmagnitude*immigration;

tobit   populist immigration logmagnitude immigmag unemployment uppertier
        austria belgium denmark finland france germany greece iceland 
        ireland italy luxembourg malta norway portugal spain 
        sweden switzerland unitedkingdom, ll(0) ltolerance (1e-5);   

        
*     ****************************************************************  *;
*               magnitude i.e. x2 = JH                                  *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    

replace JH=. if _n>51;


generate str1 txt="*";

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];

set more off;

scalar list b1 b2 b3 varb1 varb3 covb1b3;

*     ****************************************************************  *;
*      Except for in left hand side of following, do search and replace *;
*      for JH below                                                     *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<51;

set more off;

list conb in 1/20;

*     ****************************************************************  *;
*      These create conditional coefficients for b1 at JH, x3H#         *;
*     ****************************************************************  *;
*      We can write the following code as a template, then sub in the   *;
*      names of the "variables" for JH *x3 .   "variables" because they *;
*      won't be the real variables.  Instead, they'll be the variables  *;
*      created to represent the relevant values of the modifying        *;
*      variables.                                                       *;
*     ****************************************************************  *;


gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<51;
set more off;

list conse in 1/20;
gen cont= conb/conse;

list cont in 1/20;

*     ****************************************************************  *;
*      This creates a conditional t for each level of JHHH given which  *;
*      x3H is chosen                                                    *;
*     ****************************************************************  *;

gen conbS = conb;

*     ****************************************************************  *;
*       These create "shadow" (thus the "S") variables for each of the  *;
*       conditional b's.  Statistical significance indicated at 95%     *;
*       level (one-tailed).                                             *;
*     ****************************************************************  *;

replace conbS = . if abs(cont)<1.658;

list conbS in 1/20;

*     ****************************************************************  *;
*      This creates missing values for all the insignificant shadow b's.*;
*     ****************************************************************  *;
*     ****************************************************************  *;
*       Generate confidence intervals at the 95% level                  *;
*     ****************************************************************  *;
*     ****************************************************************  *;

gen a=1.658*conse;
gen top=conb+a;
gen bottom=conb-a;
set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of Immigration  on Voteshare conditional on    *;
*       Unemployment                                                    *;
*     ****************************************************************  *;
gprefs set window scheme blackbg;
gprefs set window update;
gprefs set custom1 pen2_thick 9;
graph  conb top bottom JH, psize(100) noaxis ylab( -2 0 2 4 6) xlab(0 1 2 3 4 5 ) 
yline(0) pen(95) symbol(...) c(l l[_.] l[_.])sort;  

set textsize 100;



*     ****************************************************************  *;
*       Immigration is significant whenever unemployment is larger than *;
*       1.3%.  12 observations fall into the insignificant realm (7.3%) *;
*       i.e. 12/165 observations                                        *;
*     ****************************************************************  *;


log close
